package com.alax.interfaces.service.impl;

import java.util.List;
import com.alax.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alax.interfaces.mapper.UserApiKeyMapper;
import com.alax.interfaces.domain.UserApiKey;
import com.alax.interfaces.service.IUserApiKeyService;

/**
 * 用户API密钥Service业务层处理
 * 
 * @author alax
 * @date 2025-04-10
 */
@Service
public class UserApiKeyServiceImpl implements IUserApiKeyService 
{
    @Autowired
    private UserApiKeyMapper userApiKeyMapper;

    /**
     * 查询用户API密钥
     * 
     * @param id 用户API密钥主键
     * @return 用户API密钥
     */
    @Override
    public UserApiKey selectUserApiKeyById(Long id)
    {
        return userApiKeyMapper.selectUserApiKeyById(id);
    }

    /**
     * 查询用户API密钥列表
     * 
     * @param userApiKey 用户API密钥
     * @return 用户API密钥
     */
    @Override
    public List<UserApiKey> selectUserApiKeyList(UserApiKey userApiKey)
    {
        return userApiKeyMapper.selectUserApiKeyList(userApiKey);
    }
    
    /**
     * 查询用户API密钥列表（优化字段）
     * 
     * @param userId 用户ID
     * @return 用户API密钥集合
     */
    @Override
    public List<UserApiKey> selectUserApiKeysOptimized(Long userId)
    {
        return userApiKeyMapper.selectUserApiKeysOptimized(userId);
    }

    /**
     * 新增用户API密钥
     * 
     * @param userApiKey 用户API密钥
     * @return 结果
     */
    @Override
    public int insertUserApiKey(UserApiKey userApiKey)
    {
        userApiKey.setCreateTime(DateUtils.getNowDate());
        return userApiKeyMapper.insertUserApiKey(userApiKey);
    }

    /**
     * 修改用户API密钥
     * 
     * @param userApiKey 用户API密钥
     * @return 结果
     */
    @Override
    public int updateUserApiKey(UserApiKey userApiKey)
    {
        userApiKey.setUpdateTime(DateUtils.getNowDate());
        return userApiKeyMapper.updateUserApiKey(userApiKey);
    }

    /**
     * 批量删除用户API密钥
     * 
     * @param ids 需要删除的用户API密钥主键
     * @return 结果
     */
    @Override
    public int deleteUserApiKeyByIds(Long[] ids)
    {
        return userApiKeyMapper.deleteUserApiKeyByIds(ids);
    }

    /**
     * 删除用户API密钥信息
     * 
     * @param id 用户API密钥主键
     * @return 结果
     */
    @Override
    public int deleteUserApiKeyById(Long id)
    {
        return userApiKeyMapper.deleteUserApiKeyById(id);
    }
}
